package com.xhsj.user.hr.process.hrInterviewRegistration.web;

import com.xhsj.user.utils.Message;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.*;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;

import org.springframework.web.bind.annotation.RestController;


import com.xhsj.user.hr.process.hrInterviewRegistration.service.TbHrInterviewRegistrationWorkService;
import com.xhsj.user.hr.process.hrInterviewRegistration.entity.TbHrInterviewRegistrationWork;


/**
 * <p>
 * hr面试登记表-工作记录 前端控制器
 * </p>
 *
 * @author liuqinghua
 * @since Sep 4, 2020 11:22:51 AM
 */
@Slf4j
@Api(tags = "hr面试登记表-工作记录")
@RestController
@RequestMapping("/hrInterviewRegistration/tbHrInterviewRegistrationWork")
public class TbHrInterviewRegistrationWorkController {

	@Autowired
    public TbHrInterviewRegistrationWorkService service;


	/**
	 * 保存/修改
	 * @author liuqinghua
	 * @date Sep 4, 2020 11:22:51 AM
	 */
	@ApiOperation(value = "hr面试登记表-工作记录,保存/修改", notes = "hr面试登记表-工作记录,保存和修改方法")
	@RequestMapping(value = "/save", method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('tb:hr:interview:registration:work:edit')")
	public Message save(@RequestBody TbHrInterviewRegistrationWork data){
    	try {
    		service.save(data);
			return Message.success("成功");
		} catch (Exception e) {
			log.error("保存失败:{}",e);
        	return Message.error(1,"失败");
		}

	}

	/**
	 * 通过id删除数据
	 * @author liuqinghua
	 * @date Sep 4, 2020 11:22:51 AM
	 */
	@ApiOperation(value = "hr面试登记表-工作记录删除", notes = "通过id删除hr面试登记表-工作记录信息。")
	@RequestMapping(value = "/delete", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('tb:hr:interview:registration:work:delete')")
	public Message delete(@RequestParam(value="id") Long id) {
		try {
			service.removeById(id);
        	return Message.success("成功");
		} catch (Exception e) {
			log.error("删除失败:{}",e);
            return Message.error(1,"失败");
		}

	}

	/**
	 * 批量删除
	 * @author liuqinghua
	 * @date Sep 4, 2020 11:22:51 AM
	 */
	@ApiOperation(value = "批量删除", notes = "批量删除。")
	@RequestMapping(value = "/batchDelete", method = RequestMethod.POST)
	@PreAuthorize("hasAuthority('tb:hr:interview:registration:work:delete')")
	public Message batchDelete(@RequestBody List<Long> list) {
		try {
			service.removeByIds(list);
    		return Message.success("成功");
		} catch (Exception e) {
    		log.error("删除失败:{}",e);
    		return Message.error(1,"失败");
		}
    }

    /**
    * 分页查询数据
    * @author liuqinghua
    * @date Sep 4, 2020 11:22:51 AM
    */
	@ApiOperation(value = "分页查询hr面试登记表-工作记录list", notes = "带参数查询,{\"page\": 1,\"size\": 5,......}。支持模糊查询")
	@RequestMapping(value="/findList",method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('tb:hr:interview:registration:work:view')")
	public Message findList(@RequestBody Map<String,Object> data) {
        try {
        	IPage<TbHrInterviewRegistrationWork> selectPage = service.selectPage(data);
    		return Message.success("成功",selectPage.getRecords(),selectPage.getTotal(),selectPage.getPages());
        } catch (Exception e) {
			log.error("查询异常:{}",e);
    		return Message.error(1,"失败");
        }
	}

    /**
    * 查询所有数据
    * @author liuqinghua
    * @date Sep 4, 2020 11:22:51 AM
    */
	@ApiOperation(value = "查询hr面试登记表-工作记录所有数据list", notes = "查询hr面试登记表-工作记录所有数据list。")
	@RequestMapping(value="/findAll",method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('tb:hr:interview:registration:work:view')")
	public Message findAll(){
        return Message.success("成功",service.selectAll());
	}

    /**
    * 通过id获取实体类
    * @author liuqinghua
    * @date Sep 4, 2020 11:22:51 AM
    */
	@ApiOperation(value = "通过id获取hr面试登记表-工作记录实体类", notes = "通过id获取hr面试登记表-工作记录实体类。")
	@RequestMapping(value="/getById",method = RequestMethod.GET)
	public Message getById(@RequestParam(value="id") Long id) {
    	return Message.success("成功",service.getById(id));
	}

    /**
    * 通过id查询详细信息
    * @author liuqinghua
    * @date Sep 4, 2020 11:22:51 AM
    */
	@ApiOperation(value = "通过id获取实体类详细信息", notes = "通过id获取实体类详细信息。")
	@RequestMapping(value="/detail",method = RequestMethod.GET)
	public Message detail(@RequestParam(value="id") Long id) {
    	return Message.success("成功",service.getById(id));
	}

}

